﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using CPlatePrintSys.Domain.Models;
using CPlatePrintSys.Infrastructure;
using Prism.Events;
using Prism.Ioc;
using Prism.Navigation.Regions;

namespace CPlatePrintSys.Win.Views
{
    /// <summary>
    /// HomeView.xaml 的交互逻辑
    /// </summary>
    public partial class HomeView : UserControl
    {
        public HomeView()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 点击工作空间记录进入对应工作空间
        /// </summary>
        private void WorkSpaceRecord_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            if (sender is FrameworkElement element && element.DataContext is WorkSpaceRecord record)
            {
                try
                {
                    // 获取ViewModel
                    if (DataContext is ViewModels.HomeViewModel viewModel)
                    {
                        // 导航到工作空间页面，并传递工作空间ID参数
                        var parameters = new Prism.Navigation.NavigationParameters();
                        parameters.Add("WorkSpaceId", record.Id);
                        parameters.Add("WorkSpaceName", record.Name);
                        
                        var regionManager = (IRegionManager)Prism.Ioc.ContainerLocator.Container.Resolve<IRegionManager>();
                        regionManager.RequestNavigate(ConstStrings.UI_Region_Secondary_Content, "ProcessSequenceView", parameters);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show($"进入工作空间失败: {ex.Message}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
        }
    }
}
